$(function() {
  // 获取openID
  if (args.u) {
    window.openID = args.u;
    } else {
      layer.open({
        content: '未识别用户'
        ,skin: 'msg'
        ,time: 2 //2秒后自动关闭
      });
    }

    var list = new Vue({
      el: 'html',
      data: {
        unfinishs: [],
        finisheds: []
      },
      methods: {
        addVisitor: function() {
          location.href = './addVisitor.html?u=' + openID;
        },
        toView: function(id) {
          location.href = './visitorView.html?p=' + id + '&u=' + openID;
        }
      }

  });
     // 访客列表
    $.ajax({
      type: 'POST',
      url: baseURL + '/visitorList',
      data: {
        openID: openID
      },
      success: function (data){
        console.log(data)
        list.lists = data;
        for (var i = data.length - 1; i >= 0; i--) {
          if( data[i].status == 0 ){
            data[i].status = '待审核'; 
            list.unfinishs.push(data[i]);
          }else if( data[i].status == 1 ){
            data[i].status = '同意访问'; 
            list.unfinishs.push(data[i]);
          }else if( data[i].status == 2 ){
            data[i].status = '拒绝访问'; 
            list.finisheds.push(data[i]);
          }else if(data[i].status == 3 ){
            data[i].status = '结束访问'; 
            list.finisheds.push(data[i]);
          }
        }
        // 关闭加载层
        layer.close(index);
      },
      error: function (data){
        layer.open({
          content: data.responseJSON.message
          ,skin: 'msg'
          ,time: 2 //2秒后自动关闭
        });
      }

    });
  
     // 增加访客
    $('#saveBtn').click(function() {
      location.href = './addVisitor.html?u=' + openID;
    });
});